const mergeConfig = (config1, config2) => {
  config2 = config2 || {};
  var config = {};

  ['url', 'method', 'params', 'data'].forEach(prop => {
    if (typeof config2[prop] !== 'undefined') {
      config[prop] = config2[prop];
    }
  });

  ['headers', 'auth', 'proxy'].forEach(prop => {
    if (typeof config2 === 'object') {
      config[prop] = {
        ...config1[prop],
        ...config2[prop]
      };
    }
  });

  [
    'baseURL',
    'transformRequest',
    'transformResponse',
    'paramsSerializer',
    'timeout',
    'withCredentials',
    'adapter',
    'responseType',
    'xsrfCookieName',
    'xsrfHeaderName',
    'onUploadProgress',
    'onDownloadProgress',
    'maxContentLength',
    'validateStatus',
    'maxRedirects',
    'httpAgent',
    'httpsAgent',
    'cancelToken',
    'socketPath',
    'Authorization'
  ].forEach(prop => {
    if (typeof config2[prop] !== 'undefined') {
      config[prop] = config2[prop];
    } else if (typeof config1[prop] !== 'undefined') {
      config[prop] = config1[prop];
    }
  });

  return config;
};


export default mergeConfig;
